<script setup lang="ts">
import { inject } from 'vue'
import AddOrConfirmForm from '@renderer/views/patients/components/modal/components/AddOrConfirmForm.vue'
import { useRouter } from 'vue-router'
import { useControlGlobalModal } from '@renderer/layout/hooks/useControlGlobalModal'
import { useScanStore } from '@renderer/store/pinia/scan'
import { GlobalNotification } from '@renderer/components/Toast/GlobalNotification'

const { showChooseScanModeRef } = useControlGlobalModal()
const { confirmPatientVisibleRef } = inject('patients') as any
const router = useRouter()
const handleClose = () => {
  confirmPatientVisibleRef.value = false
}
const { selectedPatientRef, modifiedPatientRef, updatePatientInfo,getPatientList } = inject('patients') as any

const updateAndScan = () => {
  const scanStore = useScanStore()
  scanStore.setScanPatientInfo(modifiedPatientRef.value)
  showChooseScanModeRef.value = true
}

const handleSave = async () => {
  try {
    await updatePatientInfo()
    await getPatientList()
    GlobalNotification({
      title: 'tips',
      message: 'add Successfully!',
      type: 'success'
    })
    handleClose()
  } catch (e) {
    console.log(e)
  }
}
</script>

<template>
  <el-dialog
    title="确定患者信息"
    width="900"
    destroy-on-close
    :before-close="handleClose"
  >
    <template #default>
      <div class="max-h-[500px] overflow-auto">
        <add-or-confirm-form type="confirm" />
      </div>
    </template>

    <template #footer>
      <el-button @click="handleSave">保存</el-button>
      <el-button @click="handleClose">取消</el-button>

      <el-button type="primary" @click="updateAndScan">保存并扫描</el-button>
    </template>
  </el-dialog>
</template>

<style scoped>

</style>
